<template>
  <div>
    <el-form :rules="rules" :model="phone" ref="fromRef">
      <el-form-item label="手机号" prop="Number">
        <el-input v-model="phone.Number" clearable />
      </el-form-item>
      <div class="from-it">
        <el-form-item label="验证码">
          <el-input v-model="phone.code" clearable class="from-inp" />
        </el-form-item>
        <el-button type="primary" class="from-btn" size="mini"
          >获取验证码</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { useStore } from 'vuex'
import { rules } from './config/phone-config'

export default defineComponent({
  setup() {
    const phone = reactive({
      Number: '',
      code: ''
    })
    const store = useStore()
    const fromRef = ref()
    const LoginPhone = () => {
      fromRef.value?.validate((valib: any) => {
        if (valib) {
          store.dispatch('login/phoneLoginAction', { ...phone })
        }
      })
    }

    return {
      phone,
      rules,
      LoginPhone,
      fromRef
    }
  }
})
</script>

<style scoped lang="less">
.from-it {
  display: flex;
  .from-btn {
    margin-left: 20px;
    height: 40px;
  }
  .from-inp {
    margin-left: 10px;
  }
}
</style>
